*Replication code for Fix 2014

*Model used to produce estimates plotted in Figure 2

logit proagency ideo_dist import impor_dist agency_dir dc chevron
precalc


*Figure 3

use "ReplicationDataForFix2014.dta" 

quietly logit proagency ideo_dist import impor_dist agency_dir dc chevron

mat def b = e(b)
mat def V = e(V)
mat list b
mat list V

program define dissgraph1,
	syntax, ideo(real)

use  "indepvars.dta", clear 
drawnorm b1-b7, means(b) cov(V)
gen XB1 = (b1*`ideo'+b2*1+b3*`ideo'+b4*agency_dir+ b5*dc+b6*chevron+b7)
gen P1 = exp(XB1)/(1+exp(XB1))
gen XB0 = (b1*`ideo'+b2*0+b3*0+b4*agency_dir+ b5*dc+b6*chevron+b7)
gen P0 = exp(XB0)/(1+exp(XB0))
gen ideo_dis = `ideo'
keep XB1 P1 XB0 P0 ideo_dis
append using "results.dta"
save "results.dta", replace
end

clear

save "results.dta", replace emptyok

forvalues ideo = 0(.25)1.137 {
  simulate, reps(1): dissgraph1, ideo(`ideo')
}
      
use "results.dta"

#delimit ;
statsby ci1_low=r(r1) ci1_med=r(r2) ci1_hi=r(r3), by(ideo_dis)
    saving("/Users/mpfix1/Desktop/ptitles_results.dta", replace):
    _pctile P1, p(2.5, 50, 97.5);

clear;

use "results.dta";

#delimit ;
statsby ci0_low=r(r1) ci0_med=r(r2) ci0_hi=r(r3), by(ideo_dis)
    saving("ptitles0_results.dta", replace):
    _pctile P0, p(2.5, 50, 97.5);

#delimit cr

use "ptitles_results.dta", clear
joinby ideo_dis using "ptitles0_results.dta", unmatched(master)

twoway line ci1_low ci1_med ci1_hi ci0_low ci0_med ci0_hi ideo_dis, sort sch(s1color) legend(off) lcolor(black black black black black black) lwidth (thin thick thin thin thick thin) lpattern(solid solid solid dash dash dash) xline(.5, lcolor(gray) lpattern(dash)) ytitle("Probability of Deference") xtitle("Ideological Distance")


